

var canCompleteCircuit = function (gas, cost) {
    let len = gas.length;
    let spare = 0;
    let minSpare = Number.MAX_SAFE_INTEGER
    let minIndex = 0;
    for (let i = 0; i < len; i++) {
        spare += gas[i] - cost[i];
        console.log(spare,"=====spare");
        console.log(minSpare,"======minsparee");
        
        if (spare < minSpare) {
            minSpare = spare;
            minIndex = i;

        }
    }
    console.log(minIndex, "===");


    return spare < 0 ? -1 : (minIndex + 1) % len;
};
let gas = [1, 2, 3, 4, 5], cost = [3, 4, 5, 1, 2]
canCompleteCircuit(gas, cost)